from rest_framework import serializers
from rest_framework.exceptions import ValidationError
from api_test.models import *


class UserInfoSerializer(serializers.ModelSerializer):
    class Meta:
        model = UserInfo #指明该序列化器处理的数据字段从模型类BookInfo参考生成
        fields = "__all__" #指明该序列化器包含模型类中的哪些字段，'__all__'指明包含所有字段

    # def validate_username(self, value):
    #     username = self.initial_data.get('username')
    #     exists = UserInfo.objects.filter(username=username).exists()
    #     if not exists:
    #         raise ValidationError('用户名已存在')
    #     return value

class ProjectSerializer(serializers.ModelSerializer):
    class Meta:
        model = Project
        fields = "__all__"

class ApiGroupSerializer(serializers.ModelSerializer):
    class Meta:
        model = ApiGroup
        fields = "__all__"

class ApiInfoSerializer(serializers.ModelSerializer):
    class Meta:
        model = ApiInfo
        fields = "__all__"

#接口参数
class ApiHeaderSerializer(serializers.ModelSerializer):
    class Meta:
        model = ApiHeader
        fields = "__all__"

class ApiQuerySerializer(serializers.ModelSerializer):
    class Meta:
        model = ApiQuery
        fields = "__all__"
class ApiBodySerializer(serializers.ModelSerializer):
    class Meta:
        model = ApiBody
        fields = "__all__"

class ApiResponseSerializer(serializers.ModelSerializer):

    class Meta:
        model = ApiResponse
        fields = "__all__"

